package com.robusta.app.auth.model;

import com.robusta.app.domain.user.UserType;
import com.robusta.app.matchers.CompositeMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;

public class UserModelMatcher extends CompositeMatcher<UserModel> {
    private UserModelMatcher() {}

    public static UserModelMatcher isAUserModel() {
        return new UserModelMatcher();
    }

    public UserModelMatcher withId(final Matcher<Long> idMatcher) {
        add(new TypeSafeMatcher<UserModel>() {
            @Override
            public boolean matchesSafely(UserModel userModel) {
                return idMatcher.matches(userModel.getId());
            }

            @Override
            public void describeTo(Description description) {
                description.appendText("with id = ");
                idMatcher.describeTo(description);
            }
        }); return this;
    }

    public UserModelMatcher withName(final Matcher<String> nameMatcher) {
        add(new TypeSafeMatcher<UserModel>() {
            @Override
            public boolean matchesSafely(UserModel userModel) {
                return nameMatcher.matches(userModel.getName());
            }

            @Override
            public void describeTo(Description description) {
                description.appendText("with name = ");
                nameMatcher.describeTo(description);
            }
        }); return this;
    }

    public UserModelMatcher withLoginName(final Matcher<String> loginNameMatcher) {
        add(new TypeSafeMatcher<UserModel>() {
            @Override
            public boolean matchesSafely(UserModel userModel) {
                return loginNameMatcher.matches(userModel.getLoginName());
            }

            @Override
            public void describeTo(Description description) {
                description.appendText("with login name = ");
                loginNameMatcher.describeTo(description);
            }
        }); return this;
    }

    public UserModelMatcher withUserType(final Matcher<UserType> userTypeMatcher) {
        add(new TypeSafeMatcher<UserModel>() {
            @Override
            public boolean matchesSafely(UserModel userModel) {
                return userTypeMatcher.matches(userModel.getUserType());
            }

            @Override
            public void describeTo(Description description) {
                description.appendText("with user type = ");
                userTypeMatcher.describeTo(description);
            }
        }); return this;
    }

    public UserModelMatcher withEmail(final Matcher<String> emailMatcher) {
        add(new TypeSafeMatcher<UserModel>() {
            @Override
            public boolean matchesSafely(UserModel userModel) {
                return emailMatcher.matches(userModel.getEmail());
            }

            @Override
            public void describeTo(Description description) {
                description.appendText("with email = ");
                emailMatcher.describeTo(description);
            }
        }); return this;
    }
}
